home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AECUR100.ARJ / CVIDINTF.C < prev    next >
C/C++ Source or Header  |  1991-11-05  |  11KB  |  439 lines

  1. /**********************************************************************
  2.  *  
  3.  *  cvidintf.c
  4.  *  
  5.  *  copyright (c) 1988,89,90,91 J. Alan Eldridge
  6.  *
  7.  *  video interface functions written in C
  8.  *  
  9.  *  11/02/91 JAE modified to work with GNU C++ (DJ Delorie's port)
  10.  *
  11.  *********************************************************************/
  12.  
  13. #include "curses.h"
  14.  
  15. #ifdef  __GNUC__
  16. #include    "aedef.h"
  17. #include    <pc.h>
  18. #define MSC50 0
  19. #define TURBOC 0
  20. #define AZTEC 0
  21. #endif
  22.  
  23. #if (MSC50 | TURBOC)
  24. #include <dos.h>
  25. #endif  /* (MSC50 | TURBOC) */
  26.  
  27. #if AZTEC
  28. #include "aztecdos.h"
  29. #endif  /* AZTEC */
  30.  
  31. #define  USE_STR_FUNCS  0  /* set to 1 to use AT video string funcs */
  32.  
  33. /**********************************************************************
  34.  *  
  35.  *  the cursor functions implement the concept of a cursor level:
  36.  *  if the cursor level is 0, the cursor is visible
  37.  *
  38.  *  each call to hidecursor() increments the level, and each
  39.  *  call to showcursor() decrements the level
  40.  *  
  41.  *  these static variable keep track of the cursor info when it is hidden
  42.  *  
  43.  *********************************************************************/
  44.  
  45. static  int hide_cnt    =   0;  /* # times cursor has been hidden ... */
  46.                                 /* if > 0, cursor is not visible */
  47. static  VID_CURS_SIZE   c_size; /* start/end line of current cursor shape */    
  48.  
  49. /**********************************************************************
  50.  *  
  51.  *  vid_mov_curs(y, x)
  52.  *  
  53.  *  move the cursor to the indicated screen coordinates
  54.  *  
  55.  *********************************************************************/
  56.  
  57. void
  58. vid_mov_curs(
  59.     int y,
  60.     int x)
  61. {
  62. #ifdef  __GNUC__
  63.     ScreenSetCursor(y, x);
  64. #else
  65.     union REGS  reg_st;
  66.   
  67.     reg_st.h.ah = VB_SET_CURS_POSN;
  68.     reg_st.h.bh = 0;
  69.     reg_st.h.dh = y;
  70.     reg_st.h.dl = x;
  71.  
  72.     int86(VID_INTR, ®_st, ®_st);
  73. #endif
  74. }
  75.  
  76. /**********************************************************************
  77.  *  
  78.  *  hidecursor()
  79.  *  
  80.  *  increment the cursor level, making it invisible and saving the
  81.  *  information necessary to restore it
  82.  *  
  83.  *********************************************************************/
  84.  
  85. void
  86. hidecursor(void)
  87. {
  88.     if (hide_cnt++ == 0) {
  89. #ifndef __GNUC__
  90.         union REGS  reg_st;
  91.  
  92.         reg_st.h.ah = VB_GET_CURS_INFO;
  93.         reg_st.h.bh = 0;
  94.         int86(VID_INTR, ®_st, ®_st);
  95.         *(short *)(&c_size) = reg_st.x.cx;
  96.         reg_st.x.cx = VB_NO_CURSOR;
  97.         reg_st.h.ah = VB_SET_CURS_SIZE;
  98.         int86(VID_INTR, ®_st, ®_st);
  99. #endif
  100.     }
  101. }
  102.  
  103. /**********************************************************************
  104.  *  
  105.  *  showcursor()
  106.  *  
  107.  *  decrement the cursor level, making it visible using the saved
  108.  *  information if the level becomes 0
  109.  *  
  110.  *********************************************************************/
  111.  
  112. void
  113. showcursor(void)
  114. {
  115.     if (hide_cnt > 0)
  116.         if (--hide_cnt == 0) {
  117. #ifndef __GNUC__
  118.             union REGS  reg_st;
  119.  
  120.             reg_st.h.ah = VB_SET_CURS_SIZE;
  121.             reg_st.x.cx = *(short *)(&c_size);
  122.             int86(VID_INTR, ®_st, ®_st);
  123. #endif
  124.         }
  125. }
  126.  
  127. /**********************************************************************
  128.  *  
  129.  *  sizecursor()
  130.  *  
  131.  *  set the size of the cursor: if it is invisible, save the
  132.  *  information for later
  133.  *  
  134.  *********************************************************************/
  135.  
  136. void
  137. sizecursor(
  138.     int start_line,
  139.     int end_line)
  140. {
  141. #ifndef __GNUC__
  142.     union REGS  reg_st;
  143.  
  144.     if (hide_cnt > 0) {
  145.         c_size.top = start_line;
  146.         c_size.bot = end_line;
  147.     } else {
  148.         reg_st.h.ah = VB_SET_CURS_SIZE;
  149.         reg_st.h.ch = start_line;
  150.         reg_st.h.cl = end_line;
  151.         int86(VID_INTR, ®_st, ®_st);
  152.     }
  153. #endif
  154. }
  155.  
  156. /**********************************************************************
  157.  *  
  158.  *  int
  159.  *  vid_get_mode()
  160.  *  
  161.  *  return the current video mode as known by the BIOS
  162.  *  
  163.  *********************************************************************/
  164.  
  165. int
  166. vid_get_mode(void)
  167. {
  168. #ifndef __GNUC__
  169.     union REGS  reg_st;
  170.     
  171.     reg_st.h.ah = VB_GET_VID_MODE;
  172.     int86(VID_INTR, ®_st, ®_st);
  173.     return reg_st.h.al;
  174. #else
  175.     return ScreenMode();
  176. #endif
  177. }
  178.     
  179. /**********************************************************************
  180.  *  
  181.  *  long vid_buf_addr(mode)
  182.  *  
  183.  *  return buffer address based on video mode
  184.  *  
  185.  *********************************************************************/
  186.  
  187. long
  188. vid_buf_addr(int mode)
  189. {
  190. #ifndef __GNUC__
  191.     long    addr;
  192.     
  193.     switch (mode) {
  194.     case VID_BandW_80x25:
  195.     case VID_COLOR_80x25:
  196.         addr = VID_COLOR_ADDR;
  197.         break;
  198.     case VID_MONO_80x25:
  199.         addr = VID_MONO_ADDR;
  200.         break;
  201.     default:
  202.         addr = 0L;
  203.         break;
  204.     }
  205.  
  206.     return addr;
  207. #else
  208.     return (long)ScreenPrimary;
  209. #endif
  210. }
  211.  
  212. /**********************************************************************
  213.  *  
  214.  *  vid_get_curs_info(), vid_set_curs_info()
  215.  *  
  216.  *  routines to get/set cursor size, posn
  217.  *  
  218.  *********************************************************************/
  219.  
  220. void
  221. vid_get_curs_info(
  222.     void    *posn,
  223.     void    *size)
  224. {
  225. #ifndef __GNUC__
  226.     union REGS  reg_st;
  227.     
  228.     reg_st.h.ah = VB_GET_CURS_INFO;
  229.     reg_st.h.bh = VB_DISP_PAGE_0;
  230.     int86(VID_INTR, ®_st, ®_st);
  231.     if (posn)
  232.         *(short *)posn = reg_st.x.dx;
  233.     if (size)
  234.         *(short *)size = reg_st.x.cx;
  235. #else
  236.     int row, col;
  237.  
  238.     ScreenGetCursor(&row, &col);
  239.     if (posn)
  240.         *(short *)posn = (row << 8) + col;
  241.     if (size)
  242.         *(short *)size = 7;
  243. #endif    
  244. }
  245.  
  246. void
  247. vid_set_curs_info(
  248.     void    *posn,
  249.     void    *size)
  250. {
  251. #ifndef __GNUC__
  252.     union REGS  reg_st;
  253.     
  254.     if (size) {
  255.         reg_st.h.ah = VB_SET_CURS_SIZE;
  256.         reg_st.h.bh = VB_DISP_PAGE_0;
  257.         reg_st.x.cx = *(short *)size;
  258.         int86(VID_INTR, ®_st, ®_st);
  259.     }
  260. #endif
  261.  
  262.     if (posn) {
  263. #ifndef __GNUC__
  264.         reg_st.h.ah = VB_SET_CURS_POSN;
  265.         reg_st.h.bh = VB_DISP_PAGE_0;
  266.         reg_st.x.dx = *(short *)posn;
  267.         int86(VID_INTR, ®_st, ®_st);
  268. #else
  269.         short   pos = *(short*)posn;
  270.  
  271.         ScreenSetCursor(pos >> 8, pos & 0xff);
  272. #endif    
  273.     }
  274. }
  275.  
  276. /**********************************************************************
  277.  *  
  278.  *  vid_save_scr(buffp)
  279.  *  
  280.  *  save the video screen image and cursor info
  281.  *  
  282.  *********************************************************************/
  283.  
  284. void
  285. vid_save_scr(VID_SCR_BUFF *buffp)
  286. {
  287.     void far    *savep;
  288.  
  289.     savep = (void far *)(buffp->v_buff);
  290. #if (MSC50 | TURBOC)
  291.     movedata(__VIDADDR.segoffs.seg, 0, 
  292.         FP_SEG(savep), FP_OFF(savep), VID_BUFF_SIZE);
  293. #endif  /* MSC50 | TURBOC */
  294. #if AZTEC
  295.     movblock(__VIDADDR.farptr, savep, VID_BUFF_SIZE);
  296. #endif  /* AZTEC */
  297. #ifdef __GNUC__
  298.     gettext(1, 1, 25, 80, savep);
  299. #endif
  300.     vid_get_curs_info(&buffp->c_posn, &buffp->c_size);
  301. }
  302.  
  303. /**********************************************************************
  304.  *  
  305.  *  vid_rest_scr(buffp)
  306.  *  
  307.  *  undoes the effect of a call to vidsave()
  308.  *  
  309.  *********************************************************************/
  310.  
  311. void
  312. vid_rest_scr(VID_SCR_BUFF *buffp)
  313. {
  314.     void far    *savep;
  315.                 
  316.     savep = (void far *)(buffp->v_buff);
  317. #if (MSC50 | TURBOC)
  318.     movedata(FP_SEG(savep), FP_OFF(savep), 
  319.         __VIDADDR.segoffs.seg, 0, VID_BUFF_SIZE);
  320. #endif  /* MSC50 | TURBOC */
  321. #if AZTEC
  322.     movblock(savep, __VIDADDR.farptr, VID_BUFF_SIZE);
  323. #endif  /* AZTEC */
  324. #ifdef __GNUC__
  325.     puttext(1, 1, 25, 80, savep);
  326. #endif
  327.     vid_set_curs_info(&buffp->c_posn, &buffp->c_size);
  328. }
  329.  
  330. /**********************************************************************
  331.  *  
  332.  *  vid_clr_scr(int attrib)
  333.  *  
  334.  *  clears the PC screen using the given video attribute
  335.  *  
  336.  *********************************************************************/
  337.  
  338. void
  339. vid_clr_scr(int attrib)
  340. {
  341. #ifndef __GNUC__
  342.     if (__USE_BIOS) {
  343.         union REGS  reg_st;
  344.         
  345.         reg_st.h.ah = VB_SCROLL_WIN_UP;
  346.         reg_st.h.al = 0;    /* # lines to scroll (0 = erase) */
  347.         reg_st.h.ch =       /* row # of upper left */
  348.         reg_st.h.cl = 0;    /* col # of upper left */
  349.         reg_st.h.dh = VID_MAX_ROWS - 1;    /* row # of lower right */
  350.         reg_st.h.dl = VID_MAX_COLS - 1;    /* col # of lower right */
  351.         reg_st.h.bh = attrib;
  352.         int86(VID_INTR, ®_st, ®_st);
  353.     } else {
  354.         VIDCHR  fillch;
  355.         
  356.         fillch.chr = ' ';
  357.         fillch.att = attrib;
  358.         memsetw(__VIDADDR.farptr, &fillch, VID_BUFF_SIZE);
  359.     }
  360. #else
  361.     int attr = ScreenAttrib;
  362.  
  363.     ScreenAttrib = attrib;
  364.     ScreenClear();
  365.     ScreenAttrib = attr;
  366. #endif    
  367. }
  368.  
  369. /**********************************************************************
  370.  *  
  371.  *  vid_upd_scr(row, col, src, cnt)
  372.  *  
  373.  *  update the video RAM at screen position (row, col) from
  374.  *  the video buffer pointed to by src, transferring cnt words
  375.  *  
  376.  *********************************************************************/
  377.  
  378. void
  379. vid_upd_scr(
  380.     int     row,
  381.     int     col,
  382.     VIDCHR  *src,
  383.     int     cnt)
  384. {
  385. #ifndef __GNUC__
  386.     if (__USE_BIOS) {
  387.         int         pos;
  388.  
  389.         hidecursor();
  390. #if (TURBOC & USE_STR_FUNCS)
  391.         if ((__MACHID.model == 0xfc) {
  392.             /* if it's an AT ... */
  393.             void far        *srcptr;
  394.             struct REGPACK  regpk_st;
  395.             
  396.             srcptr = (void far *)src;
  397.             regpk_st.r_dx = ((row << 8) | col);
  398.             regpk_st.r_bp = FP_OFF(srcptr);
  399.             regpk_st.r_es = FP_SEG(srcptr);
  400.             regpk_st.r_ax = (VB_WRITE_CHRATT_STR << 8) | VB_NOFIX_CURSOR;
  401.             regpk_st.r_cx = cnt;
  402.             intr(VID_INTR, ®pk_st);
  403.             return;
  404.         }
  405. #endif  /* TURBOC & USE_STR_FUNCS */
  406.         for (pos = 0; pos < cnt; pos++) {        
  407.             union REGS      reg_st;
  408.  
  409.             reg_st.h.ah = VB_SET_CURS_POSN;
  410.             reg_st.h.bh = VB_DISP_PAGE_0;
  411.             reg_st.h.dh = row;
  412.             reg_st.h.dl = col++;
  413.             int86(VID_INTR, ®_st, ®_st);
  414.             
  415.             reg_st.h.ah = VB_WRITE_CHR_ATT;            
  416.             reg_st.h.bh = VB_DISP_PAGE_0;
  417.             reg_st.h.al = src->chr;
  418.             reg_st.h.bl = src++->att;
  419.             reg_st.x.cx = 1;
  420.             int86(VID_INTR, ®_st, ®_st);
  421.         }
  422.         showcursor();
  423.     } else {
  424.         void far    *srcp = (void far *)src;
  425.  
  426. #if (MSC50 | TURBOC)
  427.         movedata(FP_SEG(srcp), FP_OFF(srcp), __VIDADDR.segoffs.seg, 
  428.             ((row * VID_MAX_COLS) + col) * 2, cnt * 2);
  429. #endif  /* MSC50 | TURBOC */
  430. #if AZTEC
  431.         movblock(srcp, (VIDCHR far *)(__VIDADDR.farptr) 
  432.             + (row * VID_MAX_COLS) + col, cnt * 2);
  433. #endif  /* AZTEC */
  434.     }
  435. #else
  436.     puttext(col + 1, row + 1, col + cnt, row + 1, src);
  437. #endif
  438. }
  439.